import express from 'express'
export const router = express.Router()
import store from '../../store/admin.js'
import { createConnectionPool } from '../../mysql/index.js'

const connection = await createConnectionPool()

// 商户用户列表
router.post('/adminApi/AddAdminAccount', async (req, res) => {
    const { userName, password } = req.body;

    try {
        // 从数据库中获取用户信息
        const [rows] = await connection.query('SELECT * FROM user WHERE status = 1 OR status = 2');
        console.log("rows", rows);
        // 查找符合条件的用户
        const isMerchant = rows.find(user => user.username == userName && user.password == password);
        console.log("userName, password", userName, password);
        if (!isMerchant) {
            return res.status(200).send({ code: 0, message: '账号密码错误' })
        } else if (isMerchant.user_state == 0 || !isMerchant.user_state) {
            return res.status(200).send({ code: 401, message: '账号已禁用' });
        } else {
            return res.status(200).send({ code: 1, message: '登录成功', status_info: isMerchant });
        }
    } catch (error) {
        console.error('数据库查询错误:', error);
        return res.status(500).send({ code: 0, message: '服务器内部错误' });
    }
});


export default router
